
import { InitState , Actions} from "../../utils/types"


let initState:InitState = {
    username :"13000000000",
    pwd:"123",
    role:"",
    token:localStorage.getItem("token") || ""
};


// 定义reducer
let loginReducer = (state = initState , {type, payload}:Actions ) => {
    switch(type){
        case "SAVE_ROUTES":
            localStorage.setItem("token",payload.token);
            localStorage.setItem("routes",JSON.stringify(payload.routes));
            //  更新视图
            window.location.reload();
            return {
                ...state,
                username:payload.username,
                role:payload.role,
                token:payload.token
            }
        case "CHNAGE_USER":
            return {
                ...state,
                [payload.key]:payload.value
            }
        default:
            return {
                ...state
            }
    }
};


export default loginReducer;











